#include "enemy_10_warning.h"

extern int G_W, G_H;

ENEMY_10_WARNING::ENEMY_10_WARNING(CASH *cash):QGraphicsObject()
{

    go = new SOUND_POWER(cash,"Res/Sound/Enemy/Enemy_10/warning.ogg",this);
    go->Play_Now();

    qsrand(QTime::currentTime().second());

    timer_id=startTimer(300);

    this->setZValue(0.4);                   // !!!! 0.4

    anim_enemy = new QGraphicsItemAnimation();

    enemy_time_line = new QTimeLine(4000);                                             // Скорость перемещения обьекта по траектории
    enemy_time_line->setEasingCurve( QEasingCurve::Type(24));

    enemy_time_line->setFrameRange(0, 1);
    anim_enemy->setTimeLine(enemy_time_line);
    anim_enemy->setItem(this);

    int x_x_x=10+qrand()%((G_W-300)-10+1);

    anim_enemy->setPosAt(0,QPoint(x_x_x,G_H+300));
    anim_enemy->setPosAt(0.5,QPoint(x_x_x,G_H/2));
    anim_enemy->setPosAt(1,QPoint(x_x_x,G_H+300));

    enemy_time_line->start();

    blink=false;

    counter=0;

    warning = cash->cash_pixmap->value("Res/Ships/Enemy/Enemy_10/Enemy_10_warning/warning.png");
    ship = cash->cash_pixmap->value("Res/Ships/Enemy/Enemy_10/Enemy_10_warning/1.png");

    connect(enemy_time_line,SIGNAL(finished()),SLOT(Send_Kill_Me()));

}

void ENEMY_10_WARNING::timerEvent(QTimerEvent *)
{

    ++counter;

    if(counter%3){
        blink=true;
        this->update(-20,-50,warning->width(),warning->height());
    }
    else{
        blink=false;
        this->update(-20,-50,warning->width(),warning->height());
    }

}

QRectF ENEMY_10_WARNING::boundingRect() const
{

    return QRectF(0,0,0,0);

}

void ENEMY_10_WARNING::paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *)
{

    painter->save();
    painter->drawPixmap( 0,0,*ship );

    if(blink)
        painter->drawPixmap(10,-50,*warning);

    painter->restore();

}

ENEMY_10_WARNING::~ENEMY_10_WARNING()
{
}

void ENEMY_10_WARNING::Send_Kill_Me()
{

    killTimer(timer_id);
    go->Stop();
    emit Kill_Me_Please((QGraphicsObject*)this);

}




